package ModeratorOperations;

import java.util.Vector;
import CRUD.*;

import xmlMapping.*;

public class ModeratorManagePosts {
  
    
    public void Splitposts(int postid, Post post1,Post post2) {
        PostHome ph=new PostHome();
         Post post=ph.findById(postid);
        post.setTitle(post1.getTitle());
        post.setBody(post1.getBody());
            java.sql.Date sqlDate = new java.sql.Date(new java.util.Date().getTime());
        post.setLastModified(sqlDate);
        
        
        ph.attachDirty(post);
       ph.releaseConnection();
        
        PostHome ph2=new PostHome();
       post2.setForums(post.getForums());
          
        post2.setLastModified(sqlDate);
        post2.setMember(post.getMember());
      post2.setMembers(post.getMembers());
        post2.setRank(post.getRank());
        post2.setThread(post.getThread());
        post2.setThreads(post.getThreads());
    
       ph2.persist(post2);
        
        
        
    }

    public void MergePosts(int postid, int postid1,String title) {
        
     PostHome home=new PostHome();
       Post post= home.findById(postid);
       post.setBody(post.getBody()+" "+home.findById(postid1).getBody());
       post.setTitle(title);
       home.attachDirty(post);
       home.delete(home.findById(postid1));
        
        
    }

    public void movePost(int postid, int theadid) {
       
      PostHome home=new PostHome();
      Post post=  home.findById(postid);
      post.setThread(new ThreadHome().findById(theadid));
      home.attachDirty(post);
        
        
    }

    public void deletePost(int postid) {
      //  new PostHome().session.flush();
        PostHome home=new PostHome();
        home.delete(home.findById(postid)); 
    }
    
    
//    public static void main(String[] args)
//    {
//
//
//    new ModeratorManagePosts().deletePost(1);
//
//    }
    
}
